package com.cictec.middleware.gps.engine.send.apollo;

import org.apache.camel.Exchange;
import org.apache.camel.Processor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.cic.camel.components.stomp.StompComponent;


/**
 * 车辆数据总线apollo推送 处理器
 * @author ql
 *
 */
@SuppressWarnings({ "rawtypes", "unchecked" })
@Component
public class BusChangeLineProcessor implements Processor {

	
	private static Logger logger = LoggerFactory.getLogger(BusChangeLineProcessor.class);


	@Override
	public void process(Exchange exchange) throws Exception {

		String jsonBody = (String) exchange.getIn().getBody();
		
		
		StringBuffer urlBuf = new StringBuffer("/topic/").append("changeline.");
		exchange.getIn().setHeader(StompComponent.STOMP_DESTINATION, urlBuf.toString());

		String json = JSON.toJSONString(jsonBody, SerializerFeature.WriteNullStringAsEmpty, SerializerFeature.WriteMapNullValue);
		exchange.getIn().setBody(json);

		logger.debug("can数据转发至apollo topic: {} \n message:{}", urlBuf, json);
	}

	
}
